package com.itheima.controller;

import com.itheima.domain.R;
import com.itheima.domain.User;
import com.itheima.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping
    public R add(@RequestBody User user){
        boolean save = userService.save(user);
        return R.success(save);
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id")String id){
        boolean remove = userService.removeById(id);
        return R.success(remove);
    }

    @PutMapping
    public R update(@RequestBody User user){
        boolean update = userService.updateById(user);
        return R.success(update);
    }

    @GetMapping
    public R findAll(){
        List<User> userList = userService.list();
        return R.success(userList);
    }


}